from django.db import models



# Create your models here.

class User(models.Model):
    id = models.AutoField(primary_key=True)
    username = models.CharField(max_length=15)
    password = models.CharField(max_length=18)
    def __str__(self):
        return self.username

class BookInfo(models.Model):
    id = models.AutoField(primary_key=True)
    bookname = models.CharField(max_length=15)
    author = models.CharField(max_length=50)
    price = models.IntegerField()
    date = models.IntegerField()
    booktype = models.ForeignKey('BookGroup',to_field='id',default=1)
    def __str__(self):
        return self.bookname

class BookGroup(models.Model):
    id = models.AutoField(primary_key=True)
    booktype = models.CharField(unique=True,max_length=32)
    def __str__(self):
        return self.booktype

class T_User(models.Model):
    #默认会增加一列id自增主键列
    username = models.CharField(max_length=18)
    password = models.CharField(max_length=32)
    def __str__(self):
        return self.username



class CaptionGroup(models.Model):
    '''部门表'''
    id = models.AutoField(primary_key=True)
    caption = models.CharField(max_length=10,null=False,unique=True)   #部门名字为唯一值
    ctime = models.DateTimeField(auto_now_add=True,null=True)
    utime = models.DateTimeField(auto_now=True,null=True)

class UserLevel(models.Model):
    '''职位级别表'''
    id = models.AutoField(primary_key=True)
    level = models.CharField(max_length=5,unique=True,null=False)

class UserGroup(models.Model):
    '''员工表'''
    id = models.AutoField(primary_key=True)
    name = models.CharField(max_length=16,null=False)
    passwd = models.CharField(max_length=32,null=False)
    email = models.EmailField(max_length=50,null=True)
    tel = models.IntegerField(max_length=11,null=False)
    gender_type = ((1,'男'),(2,'女'))
    gender = models.IntegerField(choices=gender_type,max_length=1,default=1)
    user_caption = models.ForeignKey('UserGroup',to_field='id',default=1)#外键一对一关联，关联字段为uid，注意，关联的字段必须是主键！
    # user_level = models.ForeignKey('UserLevel',to_field='id',default=1)






